package com.example.mybiadushoujiweishi.activity.acivitys;

import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.widget.LinearLayout;
import android.widget.Toast;


import com.example.mybiadushoujiweishi.R;
import com.example.mybiadushoujiweishi.activity.acivitys.base.BaseActivity;
import com.example.mybiadushoujiweishi.activity.acivitys.entity.Versioninfo;
import com.example.mybiadushoujiweishi.activity.acivitys.fragments.UpdateVersionFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class BanbenUpdateActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.update_baidushoujiweishi)
    LinearLayout updateBaidushoujiweishi;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_banben_update);
        setSupportActionBar(toolbar);
        ActionBar ab = getSupportActionBar();
        ab.setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public int getContentView() {
        return R.layout.activity_banben_update;
    }

    @Override
    public void initData() {

    }

    @OnClick(R.id.update_baidushoujiweishi)
    public void onViewClicked() {

        startActivityForResult(new Intent(BanbenUpdateActivity.this, ChekupdateActivity.class), 0);

    }

public void dialogshow(String msg)
{

    FragmentManager fragment=getFragmentManager();
    UpdateVersionFragment u=UpdateVersionFragment.geUpdateVersionFragment(msg);

    u.show(fragment,"");
}



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (resultCode) {
            case 1:
                dialogshow("网络连接慢,请稍后重试");
                Toast.makeText(this, "网络连接慢,请稍后重试", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                dialogshow("手机没有连接网络，请连接网络");
                Toast.makeText(this, "手机没有连接网络，请连接网络", Toast.LENGTH_SHORT).show();
                break;
            case 3:

             //  System.out.println(url+"urlurlrurlurlrurlurl");
             Versioninfo url= (Versioninfo) data.getSerializableExtra("versioninfo");
               // Toast.makeText(this, url.getApkurl(), Toast.LENGTH_SHORT).show();
                FragmentManager fragment=getFragmentManager();
                UpdateVersionFragment u=UpdateVersionFragment.geupdateversionfragment(url);

                u.show(fragment,"");

                System.out.println("3333333333333");
                Toast.makeText(this, "网络正常", Toast.LENGTH_SHORT).show();
                break;
            case 4:
              //  Toast.makeText(this, "已是最新版本", Toast.LENGTH_SHORT).show();
                dialogshow("已是最新版本");
                break;
        }
    }
}
